<%--
  Created by IntelliJ IDEA.
  User: qingx
  Date: 2018/12/1
  Time: 19:52
  To change this template use File | Settings | File Templates.
--%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
         pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt"%>

<!DOCTYPE html>
<html lang="en">
<head>
    <!-- jsp文件头和头部 -->
    <%@ include file="../base/top.jsp" %>
    <link rel="stylesheet" href="static/ace/css/ace.css" class="ace-main-stylesheet" id="main-ace-style" />
</head>

<body class="no-skin">
<div class="main-container ace-save-state" id="main-container">
    <div class="main-content">
        <div class="main-content-inner">
            <div class="page-content">
                <div class="row">
                    <div class="col-xs-12">
                        <!-- PAGE CONTENT BEGINS -->

                        <form class="form-horizontal" role="form" style="display: -webkit-flex;-webkit-justify-content: center;-webkit-align-items: center;">

                            <div style="width: 70%;">
                                <div class="widget-box">

                                    <div class="widget-header" style="text-align: center">
                                        <h4 class="widget-title">修改教师信息</h4>

                                    </div>

                                    <div class="widget-main">

                                        <div>
                                            <label>用户id</label>
                                            <br />
                                            <p class="form-control" id="user-id"></p>
                                        </div>
                                        <hr />

                                        <div>
                                            <label>工号</label>
                                            <br />
                                            <p class="form-control" id="tea-id"></p>
                                        </div>
                                        <hr />

                                        <div>
                                            <label>姓名</label>
                                            <br />
                                            <p class="form-control" id="tea-name"></p>
                                        </div>
                                        <hr />

                                        <div>
                                            <label>性别</label>
                                            <br />
                                            <p class="form-control" id="tea-sex"></p>
                                        </div>
                                        <hr />

                                        <div>
                                            <label >出生日期</label>
                                            <br />
                                            <div class="input-group">
                                                <input class="form-control date-picker" id="tea-birth" type="text" disabled data-date-format="yyyy-mm-dd" />
                                                <span class="input-group-addon">
                                                    <i class="fa fa-calendar bigger-110"></i>
                                                </span>
                                            </div>
                                        </div>
                                        <hr />

                                        <div>
                                            <label >入职年份</label>
                                            <br />
                                            <input type="text" class="form-control form-filter yearpicker" disabled id="tea-entry-year"/>
                                        </div>
                                        <hr />

                                        <div>
                                            <label>就职状态</label>
                                            <br />
                                            <select class="chosen-select form-control" id="tea-work-state" data-placeholder="Choose a State...">
                                                <option>在职</option>
                                                <option>离职</option>
                                                <option>出差</option>
                                                <option>外派</option>
                                                <option>退休</option>
                                            </select>
                                        </div>
                                        <hr />

                                        <div>
                                            <label>联系方式</label>
                                            <br />
                                            <input class="form-control" maxlength="11" id="tea-telephone"
                                                   oninput="value=value.replace(/[^\d]/g,'')">
                                        </div>
                                        <hr />

                                        <div>
                                            <label>学历</label>
                                            <br />
                                            <select class="chosen-select form-control" id="tea-education" data-placeholder="Choose a State...">
                                                <option></option>
                                                <option>学士</option>
                                                <option>硕士</option>
                                                <option>博士</option>
                                            </select>
                                        </div>
                                        <hr />

                                        <div>
                                            <label>职位</label>
                                            <br />
                                            <select class="chosen-select form-control" id="tea-position" data-placeholder="Choose a State...">
                                                <option></option>
                                                <option>讲师</option>
                                                <option>教授</option>
                                                <option>副教授</option>
                                            </select>
                                        </div>

                                        <div class="clearfix form-actions" align="center">
                                            <button class="btn btn-info" type="button" onclick="modify()">
                                                Submit
                                            </button> &nbsp; &nbsp; &nbsp;
                                            <button class="btn" type="reset">
                                                Reset
                                            </button>
                                        </div>
                                    </div>
                                </div>
                            </div>
                        </form>

                        <!-- PAGE CONTENT ENDS -->
                    </div><!-- /.col -->
                </div><!-- /.row -->
            </div><!-- /.page-content -->
        </div>
    </div><!-- /.main-content -->
    <!-- 返回顶部 -->
    <a href="#" id="btn-scroll-up" class="btn-scroll-up btn btn-sm btn-inverse">
        <i class="ace-icon fa fa-angle-double-up icon-only bigger-110"></i>
    </a>
</div>
<!-- basic scripts -->
<!-- 页面底部js¨ -->
<%@ include file="../base/foot.jsp"%>
<script type="text/javascript">
   // $(top.hangge());//关闭加载状态

   //日期框
   $('.date-picker').datepicker({autoclose: true, todayHighlight: true});

   //年份选择框
   $('.yearpicker').datepicker({
       startView: 'decade',
       minView: 'decade',
       format: 'yyyy',
       maxViewMode: 2,
       minViewMode:2,
       autoclose: true
   });

    $(function () {

        //下拉框
        if (!ace.vars['touch']) {
            $('.chosen-select').chosen({allow_single_deselect: true});
            $(window)
                .off('resize.chosen')
                .on('resize.chosen', function () {
                    $('.chosen-select').each(function () {
                        var $this = $(this);
                        $this.next().css({'width': $this.parent().width()});
                    });
                }).trigger('resize.chosen');
            $(document).on('settings.ace.chosen', function (e, event_name, event_val) {
                if (event_name != 'sidebar_collapsed') return;
                $('.chosen-select').each(function () {
                    var $this = $(this);
                    $this.next().css({'width': $this.parent().width()});
                });
            });
            $('#chosen-multiple-style .btn').on('click', function (e) {
                var target = $(this).find('input[type=radio]');
                var which = parseInt(target.val());
                if (which == 2) $('#form-field-select-4').addClass('tag-input-style');
                else $('#form-field-select-4').removeClass('tag-input-style');
            });
        }
    });

   //初始化添加数据
   $(document).ready(function(){
       var teacherInfo ="${teacherInfo}";
       $("#user-id").html("${teacherInfo.userId}");
       $("#tea-id").html("${teacherInfo.teaId}");
       $("#tea-name").html("${teacherInfo.teaName}");
       if("${teacherInfo.teaSex}" == 0){
           $("#tea-sex").html("男");
       }else{
           $("#tea-sex").html("女");
       }
       $("#tea-birth").datepicker('setDate',new Date("${teacherInfo.teaBirth}"))
       $("#tea-entry-year").datepicker('setDate',new Date("${teacherInfo.teaEntryYear}"));
       $("#tea-work-state").val("${teacherInfo.teaWorkState}");
       $("#tea-telephone").val("${teacherInfo.teaTelephone}");
       $("#tea-education").val("${teacherInfo.teaEducation}");
       $("#tea-position").val("${teacherInfo.teaPosition}");
       //更新select,否则虽然数据更改了，没刷新，结果就是没改
       $('.chosen-select').trigger("chosen:updated");
   });


   //数据校验
   function checkFormats() {
       if($("#tea-work-state").val() =="") {
           prompt_alert('warning',"就职状态不得为空",0);
           return false;
       }
       if($("#tea-telephone").val() =="") {
           prompt_alert('warning',"联系方式不得为空",0);
           return false;
       }
       if($("#tea-education").val() =="") {
           prompt_alert('warning',"教师学历不得为空",0);
           return false;
       }
       if($("#tea-position").val() =="") {
           prompt_alert('warning',"教师职位不得为空",0);
           return false;
       }
       return true;
   }

   //修改
   function modify(){
       if(checkFormats()){
           var sex;
           if ($("#tea-Sex").html() == "男"){
               sex = 0;
           }else{
               sex = 1;
           }
           var data = {
               userId:$("#user-id").html(),
               teaId:$("#tea-id").html(),
               teaName:$("#tea-name").html(),
               teaSex:sex,
               teaBirth:$("#tea-birth").val(),
               teaEntryYear:$("#tea-entry-year").val(),
               teaWorkState:$("#tea-work-state").val(),
               teaTelephone:$("#tea-telephone").val(),
               teaEducation:$("#tea-education").val(),
               teaPosition:$("#tea-position").val(),
           }
           console.log(data);
           $.ajax({
               type: "POST",
               url: "<%=basePath%>teacher/editTeacherInfo",
               data: data,
               dataType:"json",
               success: function(data){
                   if(data["success"]==true){
                       prompt_alert('success',data["msg"],0);
                   }else{
                       prompt_alert('error',data["msg"],0);
                   }
               },
               error:function(msg){
                   prompt_alert('error',"教师修改失败！",0);
               }
           });
       }
   }
</script>
</body>
</html>
